
package leagueapp;

import java.util.Random;

public class Generator {
    
    Random rand;
    
        int[] points = new int[30];
        int[] playedMatches = new int[30];
        int[] wonMatches = new int[30];
        int[] lostMatches = new int[30];
        int[] wonSets = new int[30];
        int[] lostSets = new int[30];
        int[] gainedPoints = new int[30];
        int[] lostPoints = new int[30];
        
        int ataki_skonczoneSum;
        int ataki_obronioneSum;
        int ataki_nieskuteczneSum;
        int bloki_skuteczneSum;
        int bloki_obronioneSum;
        int bloki_nieskuteczneSum;
        int asy_serwisoweSum;
        int zagrywki_przyjeteSum;
        int zagrywki_zepsuteSum;
        int przyjecia_do_siatkiSum;
        int przyjecia_podbiteSum;
        int przyjecia_nieudaneSum;
        int obrony_do_siatkiSum;
        int obrony_podbiteSum;
        int obrony_nieudaneSum;
        int rozegranie_na_pojedynczy_blokSum;
        int rozegranie_na_potrojny_blokSum;
        int nieudane_rozegranieSum;
    
    String[] polishNames = {"Maciej", "Bartlomiej", "Krzysztof", "Mateusz", "Lukasz", "Hubert", "Michal", "Robert",
            "Roman", "Wojciech", "Arkadiusz", "Tomasz", "Marcin", "Pawel", 
            "Janusz","Krystian","Maurycy","Sebastian","Zygmunt","Dominik","Aleksander","Filip","Jerzy",
            "Stanislaw","Wladyslaw","Damian","Daniel","Eugeniusz","Wlodzimierz","Ksawery"
            };
    String[] polishSurnames = {"Nowak", "Paciorek", "Niemczyk", "Skadorwa", "Kwiatkowski",
            "Malinowski", "Kowalski", "Ujazdowski", "Frankowski", "Kurek", "Zygadlo", "Zieba", "Lukomski", "Pawluk",
            "Baran", "Sienkiewicz","Wieczorek","Jablonski","Mazur","Kaczmarek","Nowicki","Michalski","Adamczyk","Adamek",
            "Krol","Jasinski","Zalewski","Zawadzki","Szewczyk","Duda","Olszewski","Majewski","Sadowski","Jezierski","Pakula",
            "Kmiecik","Bujak","Dominiak","Janas","Blinski","Piwowarczyk","Pasternak","Cholewa","Gorniak","Kubica",
            "Karolowski","Maciejewski","Robak","Rana","Kazimierski","Lato","Czerwiec","Lipiec","Piatek",
            "Tatron","Rodzina","Ociepialski","Gabka","Len","Leszcz","Umilow","Wein","Nowaczyk"};
    String[] positions = {"Receiver","Attacker","Midfield","Libero"};
    
    String[] firstPartNames = {"Grota","Kosmici","Rakieta","Turbo","Start","Parasol","Flaga","Uzbrojeni",
                           "Wojskowi","Ciemni","Gornicy","Niszczyciele","Amatorzy","Bobry"};
    String[] cities = {"Wroclaw","Poznan","Warszawa","Krakow","Lublin","Gdansk","Gdynia","Katowice","Radom",
                    "Zakopane","Szczecin","Bialystok","Pila","Bydgoszcz","Suwalki","Walbrzych"};
    String[] streets = {"Teczowa","Kamienna","Pilsudzkiego","Sienkiewicza","Polna","Bulgarska","Rumunska",
                    "Rynek","Hutnicza","Wojska Polskiego","Czekoladowa","Opolska","Warszawska"};
    
    
    public Generator(){
        rand = new Random();
    }
    public String getFormatedDate(int aDay, int aMonth, int aYear){
            String birthYearString;
            String birthMonthString;
            String birthDayString;
            birthYearString = Integer.toString(aYear);
            if (aMonth < 10){
                birthMonthString = Integer.toString(aMonth);
                birthMonthString = "0"+birthMonthString;
            }
            else { birthMonthString = Integer.toString(aMonth); }
            if (aDay < 10){
                birthDayString = Integer.toString(aDay);
                birthDayString = "0"+birthDayString;
            }
            else { birthDayString = Integer.toString(aDay); }
            String fullBirthday = birthYearString+"-"+birthMonthString+"-"+birthDayString;
            return fullBirthday;
    }
    
    public void generateTeamsAndHalls(){
        int numberOfFirstParts = firstPartNames.length;
        int numberOfCities = cities.length;
        int numberOfStreets = streets.length;
        int tempNumber;
        int capacity;
        int streetNumber;
        String teamName;
        String hallName;
        String firstPartName;
        String city;
        String street;
        String address;
        String country = "Poland";
        String league = "Polish league";
        for(int i=0; i<30; i++){
            tempNumber = rand.nextInt(numberOfFirstParts);
            firstPartName = firstPartNames[tempNumber];
            tempNumber = rand.nextInt(numberOfCities);
            city = cities[tempNumber];
            teamName = firstPartName + " " + city;
            hallName = firstPartName + " " + city + " " + "Arena";
            tempNumber = rand.nextInt(numberOfStreets);
            street = streets[tempNumber];
            tempNumber = rand.nextInt(100)+1; // Numery ulic 1-100
            streetNumber = tempNumber;
            address = street + " " + streetNumber;
            tempNumber = rand.nextInt(5000)+10000; 
            capacity = tempNumber;
            
            
            String atributes = (i+1)+","+"\""+teamName+"\""+","+"\""+country+"\""+","+"\""+league+"\""+","+"1"+","+"0"+","+"0"+","+"0"+","+"0"+","+"0"+","+"0"+","+"0"+","+"0";
            System.out.println("INSERT INTO Zespoly VALUES("+atributes+")"+";");
            atributes = (i+1)+","+"\""+hallName+"\""+","+"\""+address+"\""+","+"\""+city+"\""+","+"\""+country+"\""+","+capacity;
            System.out.println("INSERT INTO Hale VALUES("+atributes+")"+";");
            
            //System.out.println(teamName+","+country+","+league);
            //System.out.println(hallName+","+address+","+city+","+country+","+capacity);
        }
    }
    
    public void generateReferees(){
        int numberOfNames = polishNames.length;
        int numberOfSurnames = polishSurnames.length;
        int tempNumber;
        String name;
        String surname;
        String nationality;
        int birthYear;
        int birthMonth;
        int birthDay;
        String birthday;
        for(int i=0; i<30; i++){
            tempNumber = rand.nextInt(numberOfNames);
            name = polishNames[tempNumber];
            tempNumber = rand.nextInt(numberOfSurnames);
            surname = polishSurnames[tempNumber];
            nationality = "Poland";
            tempNumber = rand.nextInt(30)+1950; // Rok urodzenia z zakresu 1950-1980
            birthYear = tempNumber;
            tempNumber = rand.nextInt(12)+1; // Miesiac 1-12
            birthMonth = tempNumber;
            tempNumber = rand.nextInt(28)+1; // Dzien 1-28
            birthDay = tempNumber;
            birthday = getFormatedDate(birthDay,birthMonth,birthYear);
            
            String atributes = (i+1)+","+"\""+name+"\""+","+"\""+surname+"\""+","+"\""+birthday+"\""+","+"\""+nationality+"\"";
            System.out.println("INSERT INTO Sedziowie VALUES("+atributes+")"+";");
            //System.out.println(name+","+surname+","+birthday+","+nationality);
        }
    }
    
    public void generatePlayers(){
        int numberOfNames = polishNames.length;
        int numberOfSurnames = polishSurnames.length;
        String name;
        String surname;
        String nationality;
        String position;
        int number;
        int idClub;
        int height;
        int weight;
        int attRange;
        int defRange;
        int tempNumber;
        int birthYear;
        int birthMonth;
        int birthDay;
        for (int i=0; i<600; i++){
            tempNumber = rand.nextInt(numberOfNames);
            name = polishNames[tempNumber];
            tempNumber = rand.nextInt(numberOfSurnames);
            surname = polishSurnames[tempNumber];
            nationality = "Poland";
            tempNumber = rand.nextInt(4);
            position = positions[tempNumber];
            tempNumber = rand.nextInt(99);
            number = tempNumber;
            idClub = (i % 30) + 1;
            tempNumber = rand.nextInt(40)+170; // Wzrost z zakresu 170-210cm
            height = tempNumber;
            tempNumber = rand.nextInt(40)+60; // Waga z zakresu 60-100kg
            weight = tempNumber;
            tempNumber = rand.nextInt(65)+310; // Zasieg ataku i obrony z zakresu 310-375cm
            attRange = tempNumber;
            tempNumber = rand.nextInt(10)+20;
            defRange = attRange-tempNumber;
            tempNumber = rand.nextInt(25)+1970; // Rok urodzenia z zakresu 1970-1995
            birthYear = tempNumber;
            tempNumber = rand.nextInt(12)+1; // Miesiac 1-12
            birthMonth = tempNumber;
            tempNumber = rand.nextInt(28)+1; // Dzien 1-28
            birthDay = tempNumber;
            
            String fullBirthday = getFormatedDate(birthDay,birthMonth,birthYear);
            String atributes = (i+1)+","+"\""+name+"\""+","+"\""+surname+"\""+","+"\""+fullBirthday+"\""+","+"\""+nationality+"\""+","+"\""+position+"\""+","+number+","+idClub+","+height+","+weight+","+attRange+","+defRange;
            /*System.out.println(name+","+surname+","+fullBirthday+","+nationality+","+position+","+number+","+idClub+","+
                    height+","+weight+","+attRange+","+defRange);*/
            System.out.println("INSERT INTO Zawodnicy VALUES("+atributes+")"+";");
            //genBase.insertPlayer(name,surname,fullBirthday,nationality,position,number,idClub,height,weight,attRange,defRange);
            // W database napisalem zle string do funkcji insertPlayer, trzeba to poprawic zeby poprawnie wrzucic to do bazy
        }
    }
    
    
    public void generateStatistics(){
        int tempNumber;
        String date;
        
        int idReferee;
        int refereeNote;
        int numberOfSpectators;
        
        int ataki_skonczone;
        int ataki_obronione;
        int ataki_nieskuteczne;
        int bloki_skuteczne;
        int bloki_obronione;
        int bloki_nieskuteczne;
        int asy_serwisowe;
        int zagrywki_przyjete;
        int zagrywki_zepsute;
        int przyjecia_do_siatki;
        int przyjecia_podbite;
        int przyjecia_nieudane;
        int obrony_do_siatki;
        int obrony_podbite;
        int obrony_nieudane;
        int rozegranie_na_pojedynczy_blok;
        int rozegranie_na_potrojny_blok;
        int nieudane_rozegranie;
        
        for(int k=0; k<30; k++){
            points[k] = 0;
            playedMatches[k] = 0;
            wonMatches[k] = 0;
            lostMatches[k] = 0;
            wonSets[k] = 0;
            lostSets[k] = 0;
            gainedPoints[k] = 0;
            lostPoints[k] = 0;
        }
        int id = 1;
        for(int i=0; i<=29; i++){
            int day = 1;
            int month = 1;
            int year = 2011;
            for(int j=0; j<=29; j++){
                int setsHome = 0;
                int setsAway = 0;
                int pointsHome = 0;
                int pointsAway = 0;
                
                ataki_skonczoneSum=0;
                ataki_obronioneSum=0;
                ataki_nieskuteczneSum=0;
                bloki_skuteczneSum=0;
                bloki_obronioneSum=0;
                bloki_nieskuteczneSum=0;
                asy_serwisoweSum=0;
                zagrywki_przyjeteSum=0;
                zagrywki_zepsuteSum=0;
                przyjecia_do_siatkiSum=0;
                przyjecia_podbiteSum=0;
                przyjecia_nieudaneSum=0;
                obrony_do_siatkiSum=0;
                obrony_podbiteSum=0;
                obrony_nieudaneSum=0;
                rozegranie_na_pojedynczy_blokSum=0;
                rozegranie_na_potrojny_blokSum=0;
                nieudane_rozegranieSum=0;
                
                if(i==j) continue;
                day += 7;
                if(day > 28){
                    month++;
                    day = 1;
                }
                if(month > 12){
                    year++;
                    month = 1;
                    day = 1;
                }
                date = getFormatedDate(day,month,year);
                while(setsHome != 3 && setsAway != 3){
                    tempNumber = rand.nextInt(2);
                    if(tempNumber == 0){
                        setsHome++;
                        pointsHome += 25;
                        tempNumber = rand.nextInt(11)+13; // Punkty 13-23
                        pointsAway += tempNumber;
                    }
                    else{
                        setsAway++;
                        pointsAway += 25;
                        tempNumber = rand.nextInt(11)+13; // Punkty 13-23
                        pointsHome += tempNumber;
                    }
                }
                playedMatches[i] += 1;
                playedMatches[j] += 1;
                if(setsHome == 3){
                    wonMatches[i] += 1;
                    lostMatches[j] += 1;
                    points[i] += 2;
                    points[j] += 1;
                }
                if(setsAway == 3){
                    wonMatches[j] += 1;
                    lostMatches[i] += 1;
                    points[j] += 2;
                    points[i] += 1;
                }
                gainedPoints[i] += pointsHome;
                gainedPoints[j] += pointsAway;
                lostPoints[i] += pointsAway;
                lostPoints[j] += pointsHome;
                wonSets[i] += setsHome;
                wonSets[j] += setsAway;
                lostSets[i] += setsAway;
                lostSets[j] += setsHome;
                // System.out.println(date+", "+i+", "+i+", "+j+", "+setsHome+", "+setsAway)
                
                String atributes = id+","+"\""+date+"\""+","+(i+1)+","+(i+1)+","+(j+1)+","+setsHome+","+setsAway;
                System.out.println("INSERT INTO Wyniki VALUES("+atributes+")"+";");
                id++;
                
                tempNumber = rand.nextInt(30)+1;
                idReferee = tempNumber;
                tempNumber = rand.nextInt(9500)+500;
                numberOfSpectators = tempNumber;
                tempNumber = rand.nextInt(10)+1;
                refereeNote = tempNumber;
                
                String atributesReferee = "\""+date+"\""+","+idReferee+","+refereeNote;
                System.out.println("INSERT INTO statystyki_sedziow VALUES("+atributesReferee+")"+";");
                
                String atributesHall = "\""+date+"\""+","+(i+1)+","+numberOfSpectators;
                System.out.println("INSERT INTO statystyki_hali VALUES("+atributesHall+")"+";");
                
                
                /* Tutaj bawie sie w statystyki zawodnikow */
                
                for(int z=i+1; z<600; z+=30){
                    tempNumber = rand.nextInt(10);
                    ataki_skonczone = tempNumber;
                    tempNumber = rand.nextInt(10);
                    ataki_obronione = tempNumber;
                    tempNumber = rand.nextInt(10);
                    ataki_nieskuteczne = tempNumber;
                    tempNumber = rand.nextInt(10);
                    bloki_skuteczne = tempNumber;
                    tempNumber = rand.nextInt(10);
                    bloki_obronione = tempNumber;
                    tempNumber = rand.nextInt(10);
                    bloki_nieskuteczne = tempNumber;
                    tempNumber = rand.nextInt(4);
                    asy_serwisowe = tempNumber;
                    tempNumber = rand.nextInt(10);
                    zagrywki_przyjete = tempNumber;
                    tempNumber = rand.nextInt(10);
                    zagrywki_zepsute = tempNumber;
                    tempNumber = rand.nextInt(10);
                    przyjecia_do_siatki = tempNumber;
                    tempNumber = rand.nextInt(10);
                    przyjecia_podbite = tempNumber;
                    tempNumber = rand.nextInt(10);
                    przyjecia_nieudane = tempNumber;
                    tempNumber = rand.nextInt(10);
                    obrony_do_siatki = tempNumber;
                    tempNumber = rand.nextInt(10);
                    obrony_podbite = tempNumber;
                    tempNumber = rand.nextInt(10);
                    obrony_nieudane = tempNumber;
                    tempNumber = rand.nextInt(10);
                    rozegranie_na_pojedynczy_blok = tempNumber;
                    tempNumber = rand.nextInt(10);
                    rozegranie_na_potrojny_blok = tempNumber;
                    tempNumber = rand.nextInt(10);
                    nieudane_rozegranie = tempNumber;
                    
                    ataki_skonczoneSum += ataki_skonczone;
                    ataki_obronioneSum += ataki_obronione;
                    ataki_nieskuteczneSum += ataki_nieskuteczne;
                    bloki_skuteczneSum += bloki_skuteczne;
                    bloki_obronioneSum += bloki_obronione;
                    bloki_nieskuteczneSum += bloki_nieskuteczne;
                    asy_serwisoweSum += asy_serwisowe;
                    zagrywki_przyjeteSum += zagrywki_przyjete;
                    zagrywki_zepsuteSum += zagrywki_zepsute;
                    przyjecia_do_siatkiSum += przyjecia_do_siatki;
                    przyjecia_podbiteSum += przyjecia_podbite;
                    przyjecia_nieudaneSum += przyjecia_nieudane;
                    obrony_do_siatkiSum += obrony_do_siatki;
                    obrony_podbiteSum += obrony_podbite;
                    obrony_nieudaneSum += obrony_nieudane;
                    rozegranie_na_pojedynczy_blokSum += rozegranie_na_pojedynczy_blok;
                    rozegranie_na_potrojny_blokSum += rozegranie_na_potrojny_blok;
                    nieudane_rozegranieSum += nieudane_rozegranie;
             
                    String atributesPlayers = "\""+date+"\""+","+z+","+ataki_skonczone+","+ataki_obronione+","+ataki_nieskuteczne+","+bloki_skuteczne+","+bloki_obronione+","+bloki_nieskuteczne+","+asy_serwisowe+","+zagrywki_przyjete+","+zagrywki_zepsute+","+przyjecia_do_siatki+","+przyjecia_podbite+","+przyjecia_nieudane+","+obrony_do_siatki+","+obrony_podbite+","+obrony_nieudane+","+rozegranie_na_pojedynczy_blok+","+rozegranie_na_potrojny_blok+","+nieudane_rozegranie;
                    System.out.println("INSERT INTO statystyki_zawodnikow VALUES("+atributesPlayers+")"+";");
                }
                
                    String atributesTeams = "\""+date+"\""+","+(i+1)+","+ataki_skonczoneSum+","+ataki_obronioneSum+","+ataki_nieskuteczneSum+","+bloki_skuteczneSum+","+bloki_obronioneSum+","+bloki_nieskuteczneSum+","+asy_serwisoweSum+","+zagrywki_przyjeteSum+","+zagrywki_zepsuteSum+","+przyjecia_do_siatkiSum+","+przyjecia_podbiteSum+","+przyjecia_nieudaneSum+","+obrony_do_siatkiSum+","+obrony_podbiteSum+","+obrony_nieudaneSum+","+rozegranie_na_pojedynczy_blokSum+","+rozegranie_na_potrojny_blokSum+","+nieudane_rozegranieSum;
                    System.out.println("INSERT INTO statystyki_zespolow VALUES("+atributesTeams+")"+";");
                /* Tutaj koncze statystyki zawodnikow i zespoly */
            }
            
        }
        for(int i=0; i<30; i++){
            System.out.println("UPDATE Zespoly SET "+"Mecze_rozegrane="+playedMatches[i]+", "+"Mecze_wygrane="+wonMatches[i]+", "+"Mecze_przegrane="+lostMatches[i]+", "+"Punkty="+points[i]+", "+"Sety_wygrane="+wonSets[i]+", "+"Sety_przegrane="+lostSets[i]+", "+"Punkty_zdobyte="+gainedPoints[i]+", "+"Punkty_stracone="+lostPoints[i]+" WHERE id="+(i+1)+";");
        }
    }
}
